package com.neuedu.autosale.sys.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neuedu.autosale.entity.Pager;
import com.neuedu.autosale.entity.Result;
import com.neuedu.autosale.sys.entity.InStorage;
import com.neuedu.autosale.sys.service.InStorageService;

@Controller
public class InStorageController {
	@Autowired
	private InStorageService inStorageService;

	@RequestMapping("instorage/index")
	public String InStorageIndex() {
		return "storage/instoragelist";
	}

	@RequestMapping("instorage/list")
	@ResponseBody
	public Pager<InStorage> inStorageList(@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "rows", defaultValue = "10") Integer rows) {
		Pager<InStorage> pager = new Pager<>(page, rows);
		List<InStorage> inStoragelist = inStorageService.findListByPager(pager);
		int total = inStorageService.findTotalByPager(pager);
		pager.setRows(inStoragelist);
		pager.setTotal(total);
		return pager;
	}

	@RequestMapping("instorage/add")
	@ResponseBody
	public Result doAdd(InStorage inStorage) {
		Result result = inStorageService.add(inStorage);
		return result;
	}

	@RequestMapping("instorage/edit")
	@ResponseBody
	public Result doEdit(InStorage inStorage) {
		Result result = inStorageService.edit(inStorage);
		return result;
	}

	@RequestMapping("instorage/delete")
	@ResponseBody
	public Result doDelete(Integer inStoId) {
		List<InStorage> list = new ArrayList<InStorage>();
		list.add(new InStorage(inStoId));
		Result result = inStorageService.deleteByIds(list);
		return result;
	}

}
